﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GuessLAB.UI.Classes;
using System.Utility.Emailing;
using System.Utility;

namespace GuessLAB.UI
{
    public partial class forgetpwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {

                StandardTemplateContentLoader loader = new StandardTemplateContentLoader("ResetEmail");
                EmailDataContainer container = new EmailDataContainer(loader);
                StandardTemplateEmailer emailer = new StandardTemplateEmailer(container);
                emailer.MailContentReplace += new MailContentReplaceEventHandler(reader_MailContentReplace);
                emailer.ToMail += new MailEventHandler(chckerToMail);
                emailer.Send();
                Logger.LogMessage("email sent to - " + username.Value, LogLevel.DEBUG, LogMessageType.ApplicationMessage);

            }
            catch (Exception ex)
            {
                //   MessageUtility.LogAndGetMessageCode(ex);
                //  PageUtility.RegisterClientScriptBlockByMessageId(this, "GE0001");
            }
            Response.Redirect(Constant.LoginUrl, false);
        }


        void chckerToMail(object sender, MailEventArgs eventArgs)
        {
            eventArgs.MyMail.To.Clear();
            eventArgs.MyMail.To.Add(username.Value);
        }

        void makerCheckerReplace(object sender, MailContentEventArgs e)
        {
            //e.Content = e.Content.Replace("$$vishal$$", "test");
        }

        void reader_MailContentReplace(object sender, MailContentEventArgs e)
        {
            ActivationLink link = new ActivationLink(username.Value);
            string activatePath = link.GenerateLink();

            e.Content = e.Content.Replace("$$ResetPasswordLink$$", activatePath);
        }
    }
}